/**
 * 
 */
package hihocoder;

import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 最大得分 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int M = scanner.nextInt();
		int limit = 100001;
		int[] freq = new int[limit];
		for (int i = 0; i < N; i++) {
			freq[scanner.nextInt()]++;
		}
		scanner.close();
		int[][] dp = new int[2][M + 1];
		for (int j = 1; j < limit; j++) {// 值
			int[] tmp = new int[M + 1];
			for (int i = 1; i < M + 1; i++) {// 选出的个数
				tmp[i] = Math.max(dp[1][i], (dp[0][i - 1]) + j * freq[j]);
			}
			dp[0] = dp[1];
			dp[1] = tmp;
		}
		System.out.println(dp[1][M]);
	}

}
